package com.ghxxzx.daglcustom.controller.instance;

import com.ghxxzx.daglcustom.controller.instance.service.InstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

@Controller
@RequestMapping("/instance")
public class InstanceImageController {

	@Autowired
	private InstanceService instanceService;

	/**
	 * 获取图片
	 * @throws Exception 
	 */
	@RequestMapping("/getImg")
	public void getImg(String processInstanceId, HttpServletResponse response) throws Exception {
		response.setContentType("image/jpg"); // 设置返回的文件类型

		byte[] bytes = instanceService.getProcessImage(processInstanceId);

		OutputStream os = response.getOutputStream();
		os.write(bytes);
		os.flush();
		os.close();
	}
}
